package managedBean.admin;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

import controller.admin.DashboardController;
import dto.admin.DashboardDTO;
import dto.search.ProfileDTO;

@ManagedBean(name = "dashboardManagedBean")
@ViewScoped
public class DashboardManagedBean implements Serializable {

	private static final long serialVersionUID = -6163035762934896459L;
	@ManagedProperty(value = "#{dashboardController}")
	private DashboardController dashboardController;

	/*
	 * Profiles added last week,last month,last year casts if any Donut chart
	 * with profession slices drill down with income Bar chart with income Male
	 * vs female ratio
	 * male femal count
	 * count by profession
	 * bar chart with income
	 * 
	 */
	private long lstWkCnt;
	private long lstMnthCnt;
	private long lstYrCnt;
	private long lstWkRecUpdtCnt;
	private long lstMnthRecUpdtCnt;
	private long lstYrRecUpdtCnt;
	private DashboardDTO dto;
	private List<ProfileDTO> list;
	private int maleCnt;
	private int femaleCnt;
	private Map<String,Long> professionMap;
	private Map<Integer,Long> heightMap;
	private Map<String,Long> starMap;
	private Map<String,Long> rasiMap;
	
	@PostConstruct
	public void init() {
		dto = new DashboardDTO();
		dto.setTenantId("8P2");
		try {
			dto = dashboardController.getCounts(dto);
			lstMnthCnt = dto.getLstMnthRecCrtCnt();
			lstWkCnt = dto.getLstWkRecCrtCnt();
			lstYrCnt = dto.getLstYrRecCrtCnt();
			lstMnthRecUpdtCnt = dto.getLstMnthRecUpdtCnt();
			lstWkRecUpdtCnt = dto.getLstWkRecUpdtCnt();
			lstYrRecUpdtCnt = dto.getLstYrRecUpdtCnt();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		professionMap=new LinkedHashMap<String, Long>();
		heightMap=new LinkedHashMap<Integer, Long>();
		starMap= new LinkedHashMap<String, Long>();
		rasiMap =new LinkedHashMap<String, Long>();
		try {
			list=dashboardController.findAll("8P2");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for(ProfileDTO dto:list){
			if(dto.getGender().equalsIgnoreCase("M")){
				maleCnt++;
			}else{
				femaleCnt++;
			}
			if(professionMap.containsKey(dto.getOccupation())){
				Long cnt=professionMap.get(dto.getOccupation());
				professionMap.put(dto.getOccupation(),cnt++);
			}else{
				professionMap.put(dto.getOccupation(), 1l);
			}
			if(heightMap.containsKey(dto.getHeight())){
				Long cnt=heightMap.get(dto.getHeight());
				heightMap.put(dto.getHeight(),cnt++);
			}else{
				heightMap.put(dto.getHeight(), 1l);
			}
			if(starMap.containsKey(dto.getStar())){
				Long cnt=starMap.get(dto.getStar());
				starMap.put(dto.getStar(),cnt++);
			}else{
				starMap.put(dto.getStar(), 1l);
			}
			if(rasiMap.containsKey(dto.getRasi())){
				Long cnt=rasiMap.get(dto.getRasi());
				rasiMap.put(dto.getRasi(),cnt++);
			}else{
				rasiMap.put(dto.getRasi(), 1l);
			}
		}
		
	}

	/**
	 * @return the dashboardController
	 */
	public DashboardController getDashboardController() {
		return dashboardController;
	}

	/**
	 * @param dashboardController
	 *            the dashboardController to set
	 */
	public void setDashboardController(DashboardController dashboardController) {
		this.dashboardController = dashboardController;
	}

	/**
	 * @return the lstWkCnt
	 */
	public long getLstWkCnt() {
		return lstWkCnt;
	}

	/**
	 * @param lstWkCnt
	 *            the lstWkCnt to set
	 */
	public void setLstWkCnt(long lstWkCnt) {
		this.lstWkCnt = lstWkCnt;
	}

	/**
	 * @return the lstmnthCnt
	 */
	public long getLstMnthCnt() {
		return lstMnthCnt;
	}

	/**
	 * @param lstmnthCnt
	 *            the lstmnthCnt to set
	 */
	public void setLstMnthCnt(long lstMnthCnt) {
		this.lstMnthCnt = lstMnthCnt;
	}

	/**
	 * @return the lstYrCnt
	 */
	public long getLstYrCnt() {
		return lstYrCnt;
	}

	/**
	 * @param lstYrCnt
	 *            the lstYrCnt to set
	 */
	public void setLstYrCnt(long lstYrCnt) {
		this.lstYrCnt = lstYrCnt;
	}

	/**
	 * @return the serialversionuid
	 */
	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	/**
	 * @return the dto
	 */
	public DashboardDTO getDto() {
		return dto;
	}

	/**
	 * @param dto
	 *            the dto to set
	 */
	public void setDto(DashboardDTO dto) {
		this.dto = dto;
	}

	/**
	 * @return the lstWkRecUpdtCnt
	 */
	public long getLstWkRecUpdtCnt() {
		return lstWkRecUpdtCnt;
	}

	/**
	 * @param lstWkRecUpdtCnt
	 *            the lstWkRecUpdtCnt to set
	 */
	public void setLstWkRecUpdtCnt(long lstWkRecUpdtCnt) {
		this.lstWkRecUpdtCnt = lstWkRecUpdtCnt;
	}

	/**
	 * @return the lstMnthRecUpdtCnt
	 */
	public long getLstMnthRecUpdtCnt() {
		return lstMnthRecUpdtCnt;
	}

	/**
	 * @param lstMnthRecUpdtCnt
	 *            the lstMnthRecUpdtCnt to set
	 */
	public void setLstMnthRecUpdtCnt(long lstMnthRecUpdtCnt) {
		this.lstMnthRecUpdtCnt = lstMnthRecUpdtCnt;
	}

	/**
	 * @return the lstYrRecUpdtCnt
	 */
	public long getLstYrRecUpdtCnt() {
		return lstYrRecUpdtCnt;
	}

	/**
	 * @param lstYrRecUpdtCnt
	 *            the lstYrRecUpdtCnt to set
	 */
	public void setLstYrRecUpdtCnt(long lstYrRecUpdtCnt) {
		this.lstYrRecUpdtCnt = lstYrRecUpdtCnt;
	}

	/**
	 * @return the list
	 */
	public List<ProfileDTO> getList() {
		return list;
	}

	/**
	 * @param list the list to set
	 */
	public void setList(List<ProfileDTO> list) {
		this.list = list;
	}

	/**
	 * @return the maleCnt
	 */
	public int getMaleCnt() {
		return maleCnt;
	}

	/**
	 * @param maleCnt the maleCnt to set
	 */
	public void setMaleCnt(int maleCnt) {
		this.maleCnt = maleCnt;
	}

	/**
	 * @return the femaleCnt
	 */
	public int getFemaleCnt() {
		return femaleCnt;
	}

	/**
	 * @param femaleCnt the femaleCnt to set
	 */
	public void setFemaleCnt(int femaleCnt) {
		this.femaleCnt = femaleCnt;
	}

	/**
	 * @return the professionMap
	 */
	public Map<String, Long> getProfessionMap() {
		return professionMap;
	}

	/**
	 * @param professionMap the professionMap to set
	 */
	public void setProfessionMap(Map<String, Long> professionMap) {
		this.professionMap = professionMap;
	}

	/**
	 * @return the heightMap
	 */
	public Map<Integer, Long> getHeightMap() {
		return heightMap;
	}

	/**
	 * @param heightMap the heightMap to set
	 */
	public void setHeightMap(Map<Integer, Long> heightMap) {
		this.heightMap = heightMap;
	}

	/**
	 * @return the starMap
	 */
	public Map<String, Long> getStarMap() {
		return starMap;
	}

	/**
	 * @param starMap the starMap to set
	 */
	public void setStarMap(Map<String, Long> starMap) {
		this.starMap = starMap;
	}

	/**
	 * @return the rasiMap
	 */
	public Map<String, Long> getRasiMap() {
		return rasiMap;
	}

	/**
	 * @param rasiMap the rasiMap to set
	 */
	public void setRasiMap(Map<String, Long> rasiMap) {
		this.rasiMap = rasiMap;
	}

	public ArrayList<Entry<Integer, Long>> getHeightList(){
		return new ArrayList<Entry<Integer, Long>>(heightMap.entrySet());
	}
	public ArrayList<Entry<String, Long>> getStarList(){
		return new ArrayList<Entry<String, Long>>(starMap.entrySet());
	}
	public ArrayList<Entry<String, Long>> getProfessionList(){
		return new ArrayList<Entry<String, Long>>(professionMap.entrySet());
	}
	

}
